package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliyunOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version: 1.0
 * @Author: 李佳毅
 * @description:
 * @date: 2025-07-06 20:49
 */
@RestController
@RequestMapping("/admin/common")
@Slf4j
public class CommonController {

    //自动注入阿里云OSS的工具类
    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;

    //文件上传
    @RequestMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("文件上传");
        String url = aliyunOSSUtils.uploadFile(file.getInputStream(), file.getOriginalFilename());
        return url != null ? Result.success(url) : Result.error("文件上传失败");
    }
}
